/* eslint-disable eqeqeq */
import { getuser, setuser } from '../../utils/storage'
import { request, wxlogin } from '../../utils/https'
import { getusers } from '../../utils/interfaces'

export default {
  name: 'Switchaccount',
  data () {
    return {
      user: [],
      ID: ''
    }
  },
  async onLoad () {
    const { ID } = await getuser()
    this.ID = ID
    const code = await wxlogin()
    const data = await request(getusers, {
      data: {
        code
      }
    })
    this.user = data
  },
  methods: {
    async change (data) {
      const { ID } = await getuser()
      if (data.ID != ID) {
        await setuser(data)
      }
      this.ID = data.ID
      wx.showToast({
        title: '成功',
        icon: 'success',
        duration: 2000
      })
    }
  }
}
